﻿@{
    ViewBag.Title = "List";
    Layout = "~/Views/Shared/_PageLayout.cshtml";
}
@section HeadSection
{
    <script type="text/javascript">
        $(function () {
            bindReUserCombobox("selReUser");
        });

        var url = "";
        $(function() {
            $('#BatchDetailList').datagrid({
                title: '批量充值明细管理',
                iconCls: 'icon-edit',
                url: '/batch/DetailList',
                striped: true,
                idField: 'Id',
                border: true,
                loadMsg: '数据加载中...',
                singleSelect: true,
                pagination: true,
                pageSize: 20,
                pageList: [15, 20, 25, 30],
                frozenColumns: [[{ field: 'ck', checkbox: true }]],
                columns: [
                    [
                        { field: 'Id', title: 'Id', width: 60 },
                        { field: 'ProjectName', title: '所属项目', width: 140 },
                        { field: 'BatchName', title: '批次', width: 120 },
                        { field: 'MobileNum', title: '手机号', width: 100, align: 'center' },
                        { field: 'RechValue', title: '充值金额', width: 80, align: 'center' },
                        {
                            field: 'RechStatus',
                            title: '充值状态',
                            width: 70,
                            align: 'center',
                            formatter: function(val, rec) {
                                if (val == 1) {
                                    return "<font style='color:green;'>充值成功</font>";
                                } else if (val ==2) {
                                    return "<font style='color:red;'>充值失败</font>";
                                } else if (val == 0) {
                                    return "<span style='color:blue'>待充值</span>";
                                }  
                            }
                        },
                        { field: 'RechMsg', title: '异常信息', width: 150, align: 'center' },
                         
                        {
                            field: 'RechTime',
                            title: '充值时间',
                            width: 120,
                            formatter: function(val, rec) {
                                return JSONDateToJSDate(val);
                            }
                        },
                        {
                            field: 'AddTime',
                            title: '添加时间',
                            width: 120,
                            formatter: function(val, rec) {
                                if (val) {
                                    return JSONDateToJSDate(val);
                                } else {
                                    return "";
                                }
                            }
                        },
                        //
                        //{
                         //   field: 'opt',
                        //    title: '失败补充',
                        //    align: 'center',
                        //    width: 70,
                        //    formatter: function(val, rec) {
                        //        if (rec.RechargeStatus == 0 || rec.RechargeStatus == 3) {
                        //            return '<a href="javascript:void(0);" onclick="if(confirm(\'确认补充吗？\')) { Recharge(' + rec.RCID + ');}" style="color:orangered;">补充</a>';
                        //        }
                        //    }
                        //}
                    ]
                ],
                toolbar: []
            });

            //尺寸
            $('#BatchDetailList').datagrid('resize');

            //加载搜索框//在这个样式下。加载搜索框的div
            $(".datagrid-toolbar").append($("#divsearch"));
        });

        //搜索
        function doSearch() {
            $('#BatchDetailList').datagrid('load', { reUserId: $("#selReUser").combobox("getValue"), batchName: $("#batchName").val(), mobileNum: $("#mobileNum").val(), rechStatus: $("#selRechStatus").combobox("getValue")});
        }

        //补发充值
        function Recharge(rcId) {
            $.post("RechargeAgain", { rcId: rcId }, function(data) {
                alert(data.msg);
                $('#BatchDetailList').datagrid('reload');

            }, "json");
        }

        function Export() {
            var userId = $("#selReUser").combobox("getValue");
            var batchName = $("#batchName").val();
            var mobileNum = $("#mobileNum").val();
            var rechStatus = $("#selRechStatus").combobox("getValue");           

            var form = $("<form>");
            form.attr('style', 'display:none');
            form.attr('target', '');
            form.attr('method', 'post');
            form.attr('action', 'Export');

            var input1 = $('<input>');
            input1.attr('type', 'hidden');
            input1.attr('name', 'rechStatus');
            input1.attr('value', rechStatus);

            var input2 = $('<input>');
            input2.attr('type', 'hidden');
            input2.attr('name', 'reUserId');
            input2.attr('value', userId);

            var input3 = $('<input>');
            input3.attr('type', 'hidden');
            input3.attr('name', 'batchName');
            input3.attr('value', batchName);

            var input4 = $('<input>');
            input4.attr('type', 'hidden');
            input4.attr('name', 'mobileNum');
            input4.attr('value', mobileNum);           

            $('body').append(form);
            form.append(input1);
            form.append(input2);
            form.append(input3);
            form.append(input4);            
            form.submit();
            form.remove();
        }
    </script>
}
<div id="divsearch" style="padding:5px;height:auto;">     
        充值项目：<select id="selReUser" class="easyui-combobox" style="width: 180px">
            <option value="">请选择</option>           
        </select>&nbsp;&nbsp;&nbsp;&nbsp;
        充值结果：<select id="selRechStatus" class="easyui-combobox">
            <option value="-1">所有</option>
            <option value="0">待充值</option>    
            <option value="1">成功</option>
            <option value="2">失败</option>
        </select>
        批次：<input type="text" name="batchName" id="batchName" style="width: 150px" />&nbsp;&nbsp;&nbsp;&nbsp; 
        充值手机：<input type="text" name="mobileNum" id="mobileNum" style="width: 100px" />&nbsp;&nbsp;&nbsp;&nbsp;      
        <a href="#" class="easyui-linkbutton" onclick="doSearch();" iconcls="icon-search">搜索</a>
        <a href="#" class="easyui-linkbutton" onclick="Export();" iconcls="icon-redo">导出</a>
 
</div>
<table id="BatchDetailList" toolbar="#divsearch"></table>
